package com.rightsidetech.http.controller.agentAdmin.statis;

import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.CodeIdEnum;
import com.rightsidetech.commom.utils.BeanValidator;
import com.rightsidetech.http.aspect.Auth;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.system.service.SysAgentInfoService;
import com.rightsidetech.trade.dtos.request.TdOrderSalesVolumeDayStatisReq;
import com.rightsidetech.trade.dtos.response.TdOrderIncomeRefundDayStatisResp;
import com.rightsidetech.trade.dtos.response.TdOrderSalesVolumeDayStatisResp;
import com.rightsidetech.trade.service.TdStatisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;

@RestController
@RequestMapping("/agentAdmin/statis")
@ShenyuSpringMvcClient(path = "/agentAdmin/statis/**")
@Api(tags = "agentAdmin:统计相关")
public class SysAgentStatisController extends BaseController {

    @Resource
    private TdStatisService tdStatisService;
    @Resource
    private SysAgentInfoService sysAgentInfoService;

    @Log
    @Token
    @ApiOperation("用户销量报表 列表")
    @Auth(bizType = Auth.AGENT)
    @GetMapping("/orderSalesVolumeDayPage")
    @ApiOperationSupport(ignoreParameters = {"agentInfoId","areaId"})
    public ResponseData<PageInfo<TdOrderSalesVolumeDayStatisResp>> orderSalesVolumeDayStatisPage(TdOrderSalesVolumeDayStatisReq req) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData<>(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }

        Long agentInfoId = sysAgentInfoService.findAgentInfoId(Long.parseLong(getAttribute()));
        req.setAgentInfoId(agentInfoId);

        return tdStatisService.orderSalesVolumeDayStatisPage(req);
    }


    @Log
    @Token
    @ApiOperation("用户财务报表 列表")
    @Auth(bizType = Auth.AGENT)
    @GetMapping("/orderIncomeRefundDayPage")
    @ApiOperationSupport(ignoreParameters = {"agentInfoId","areaId"})
    public ResponseData<PageInfo<TdOrderIncomeRefundDayStatisResp>> orderIncomeRefundDayStatisPage(TdOrderSalesVolumeDayStatisReq req) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData<>(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }


        Long agentInfoId = sysAgentInfoService.findAgentInfoId(Long.parseLong(getAttribute()));
        req.setAgentInfoId(agentInfoId);

        return tdStatisService.orderIncomeRefundDayStatisPage(req);
    }

}
